<template>
	<view>
		<view class="searchWrap" @click="inputFocus">
			<image src="../static/img/book/glasses.png"></image>
			<input type="text" v-model="keyword" @confirm="search" placeholder-style="color: #ccc;font-size: 28rpx"
				:placeholder="placeholder">
			<view v-if="showBtn" class="searchBtn" @click="search">搜索</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			showBtn: {
				type: Boolean,
				default: true
			},
			placeholder: {
				type: String,
				default: '搜索书名/作者'
			}
		},
		data() {
			return {
				isfocus: false,
				keyword: ''
			}
		},
		watch: {
			// keyword:{
			// 	handler(val){
			// 		if(val !== ''){
			// 			this.placeholder = ''
			// 		}else{
			// 			this.placeholder = '搜索书名/isbn/作者'
			// 		}
			// 	},
			// 	immediate: true
			// }
		},
		methods: {
			inputFocus() {
				this.isfocus = true
			},
			inputHandler(e) {
				this.keyword = e.detail.value
			},
			search() {
				// if(!this.keyword){
				// 	return
				// }
				this.$emit('search', this.keyword)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.searchWrap {
		box-sizing: border-box;
		position: relative;
		height: 70rpx;
		// line-height: 70rpx;
		border-radius: 32rpx;
		border: 2rpx solid #2ca1ff;

		image {
			display: inline-block;
			width: 30rpx;
			height: 30rpx;
			margin-left: 30rpx;
			margin-top: 18rpx;
		}

		input {
			font-size: 24rpx;
			display: inline-block;
			// margin-top: 15rpx;
			width: 60%;
			height: 66rpx;
			margin-top: 0;
			line-height: 66rpx;
			margin-left: 20rpx;
			vertical-align: top;
		}

		.searchBtn {
			position: absolute;
			width: 150rpx;
			height: 67rpx;
			line-height: 66rpx;
			border-radius: 30rpx;
			text-align: center;
			top: 0;
			right: 0;
			font-size: 36rpx;
			color: #ffffff;
			background: #2ca1ff;
		}
	}
</style>
